﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace LogClass
{
    public static class LogIt
    {
        public static bool loggingEnabled;
        public static string logName;
        public static string ServiceName;
        public static EventLog log;
        public static bool bFullLog;

        public static void LogInit(string logname, string servicename, bool blog)
        {
            logName = logname;
            loggingEnabled = blog;
            ServiceName = servicename;

            if (!EventLog.SourceExists(servicename))
                EventLog.CreateEventSource(ServiceName, logName);
            log = new EventLog();
            log.Source = logName;
        }

        public static void Log(string message, EventLogEntryType type)
        {
            if (loggingEnabled)
            {
                if ((type == EventLogEntryType.Error) || (bFullLog))
                    log.WriteEntry(message, type);
            }
        }

        public static void Log(string message)
        {
            if (loggingEnabled)
                log.WriteEntry(message, EventLogEntryType.Information);
        }

        public static void Log(Exception e)
        {
            if (loggingEnabled)
                log.WriteEntry(e.Message + "\n" + e.StackTrace, EventLogEntryType.Error);
        }

        public static void ForceLog(string message)
        {
            log.WriteEntry(message, EventLogEntryType.Information);
        }

    }
}
